/**
 * @Author: YU
 * @Date: 2021-10-24 16:16:36
 * @LastEditTime: 2021-10-24 16:22:27
 * @LastEditors: YU
 * @Description:封装axios
 */

import axios from 'axios'
import store from '@/store'

const request = axios.create({
  timeout: 20000,
  baseURL: 'http://127.0.0.1:8888/api/private/v1/'
})

// 设置请求拦截器，除了登录意外的接口都要添加请求头消息
request.interceptors.request.use(
  function (config) {
    const token = store.state.token
    if (token) {
      config.headers.Authorization = `${token}`
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)

export default request
